package com.edu.test;

import com.edu.bean.Book;
import com.edu.bean.Order;
import com.edu.mapper.BookMapper;
import com.edu.mapper.OrderMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/*
 * @Author:mx
 * @Date:2025/10/15-9:01:17
 */
public class MyTest02 {

    private SqlSession session ;

    @Before
    public void init() throws IOException {
        String path = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(path);
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        session = sessionFactory.openSession();
    }


    @Test
    public void test01(){
        OrderMapper orderMapper = session.getMapper(OrderMapper.class);
        Order order = orderMapper.selectById(1);
        System.out.println(order);
    }


    @Test
    public void test02(){
        OrderMapper orderMapper = session.getMapper(OrderMapper.class);
        Order query = new Order();
        query.setOrderId(1);
        query.setProType("电子产品");
        orderMapper.selectOrders(query);
    }

    @Test
    public void test03(){
        OrderMapper orderMapper = session.getMapper(OrderMapper.class);

        orderMapper.selectOrders2("2024-1-1","2024-01-31");
    }

    @Test
    public void test04(){
        OrderMapper orderMapper = session.getMapper(OrderMapper.class);
        Map<String,Object> query = new HashMap<>();
        query.put("proType","电子产品");
        query.put("end","2024-1-31");
        orderMapper.selectOrders3(query);
    }


    @Test
    public void test05(){
        OrderMapper orderMapper = session.getMapper(OrderMapper.class);
        Order order = new Order();
        order.setProName("二向箔");
//        order.setProType("武器");
        order.setProPrice(25.0);
        order.setOrderDate(new Date());
        orderMapper.insertOrder(order);
    }

    @Test
    public void test06(){
        OrderMapper orderMapper = session.getMapper(OrderMapper.class);
        Order order = new Order();
        order.setOrderId(2);
        order.setProName("二向箔");
        order.setProType("武器");
        order.setProPrice(25.0);
        order.setOrderDate(new Date());
        orderMapper.updateOrder(order);
    }


}
